package com.loan.web.pdf.controller.create;

import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.AjaxResult;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.common.utils.poi.ExcelUtil;
import com.loan.system.create.domain.AssistPdfBaseConf;
import com.loan.system.create.service.IAssistPdfBaseConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * PDF基本配置Controller
 *
 * @author Sophia
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/system/base")
public class AssistPdfBaseConfController extends BaseController {
    @Autowired
    private IAssistPdfBaseConfService assistPdfBaseConfService;

    /**
     * 查询PDF基本配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:base:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssistPdfBaseConf assistPdfBaseConf) {
        startPage();
        List<AssistPdfBaseConf> list = assistPdfBaseConfService.selectAssistPdfBaseConfList(assistPdfBaseConf);
        return getDataTable(list);
    }

    /**
     * 查询所有PDF基本配置列表
     */
    @GetMapping("/listAll")
    public AjaxResult listAll() {
        List<AssistPdfBaseConf> list = assistPdfBaseConfService.selectAssistPdfBaseConfList(null);
        return AjaxResult.success(list);
    }


    /**
     * 导出PDF基本配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:base:export')")
    @Log(title = "PDF基本配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssistPdfBaseConf assistPdfBaseConf) {
        List<AssistPdfBaseConf> list = assistPdfBaseConfService.selectAssistPdfBaseConfList(assistPdfBaseConf);
        ExcelUtil<AssistPdfBaseConf> util = new ExcelUtil<AssistPdfBaseConf>(AssistPdfBaseConf.class);
        util.exportExcel(response, list, "PDF基本配置数据");
    }

    /**
     * 获取PDF基本配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:base:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(assistPdfBaseConfService.selectAssistPdfBaseConfById(id));
    }

    /**
     * 新增PDF基本配置
     */
    @PreAuthorize("@ss.hasPermi('system:base:add')")
    @Log(title = "PDF基本配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssistPdfBaseConf assistPdfBaseConf) {
        return toAjax(assistPdfBaseConfService.insertAssistPdfBaseConf(assistPdfBaseConf));
    }

    /**
     * 修改PDF基本配置
     */
    @PreAuthorize("@ss.hasPermi('system:base:edit')")
    @Log(title = "PDF基本配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssistPdfBaseConf assistPdfBaseConf) {
        return toAjax(assistPdfBaseConfService.updateAssistPdfBaseConf(assistPdfBaseConf));
    }

    /**
     * 删除PDF基本配置
     */
    @PreAuthorize("@ss.hasPermi('system:base:remove')")
    @Log(title = "PDF基本配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(assistPdfBaseConfService.deleteAssistPdfBaseConfByIds(ids));
    }
}
